﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using Isaac.Joy.Identity.Module;
using Isaac.Joy.Menu.Module;
using Isaac.Joy.Serialize;
using UIShell.OSGi;

namespace Isaac.Joy.Identity.Web.DtCms
{
    public class MenusConfig : IMenus
    {
        private IRepository _repository;

        protected IRepository Repository
        {
            get
            {
                return _repository ?? (_repository = BundleRuntime.Instance.GetFirstOrDefaultService<IRepository>());
            }
        }

        public IEnumerable<IMenu> Menus
        {
            get
            {
                var path = Path.Combine(Activator.BundleContext.Bundle.Location, "Menus.xml");
                return XmlSerializable.LoadFromXml<List<Menu.Module.Menu>>(path);
            }
        }
    }
}